<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "user".
 *
 * @property integer $user_id
 * @property string $name
 * @property string $email
 * @property string $photo
 * @property string $source
 * @property string $openid
 * @property string $unionid
 *
 * @property Comment[] $comments
 * @property DataRelationship[] $dataRelationships
 * @property Notebook[] $notebooks
 * @property ReadUser[] $readUsers
 */
class User extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'email', 'photo', 'source', 'openid', 'unionid'], 'required'],
            [['source'], 'string'],
            [['name', 'email'], 'string', 'max' => 50],
            [['photo'], 'string', 'max' => 200],
            [['openid', 'unionid'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'user_id' => 'User ID',
            'name' => 'Name',
            'email' => 'Email',
            'photo' => 'Photo',
            'source' => 'Source',
            'openid' => 'Openid',
            'unionid' => 'Unionid',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getComments()
    {
        return $this->hasMany(Comment::className(), ['user_id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDataRelationships()
    {
        return $this->hasMany(DataRelationship::className(), ['user_id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getNotebooks()
    {
        return $this->hasMany(Notebook::className(), ['user_id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getReadUsers()
    {
        return $this->hasMany(ReadUser::className(), ['user_id' => 'user_id']);
    }
}
